<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="/home/css/_reset.css" />
		<link rel="stylesheet" type="text/css" href="/home/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="/home/css/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="/home/css/receiving.css" />
	</head>

	<body style="overflow-x: hidden;">
		<div class="receiving">
			<div class="top">
				<a href="javascript:history.back(-1)" class="back">
					<i class="iconfont">&#xe615;</i></a>
					添加收货地址
			</div>
			<div class="input container">
				<p class="row">
					<span class="col-xs-4">收货人</span>
					<input type="text" placeholder="请输入收货人姓名" class="col-xs-8" value="" id="a_name" />
				</p>
				<p class="row">
					<span class="col-xs-4">联系电话</span>
					<input type="text" placeholder="请输入正确的联系的电话" class="col-xs-8" value="" id="a_tel" />
				</p>
				<p class="row">
					<span class="col-xs-4">所在地区</span>
					<input type="text" placeholder="请输入如：广州市" class="col-xs-8" value="" id="a_region" />
				</p>
				<p class="row">
					<span class="col-xs-4">详细地址</span>
					<!--<input type="text" placeholder="请输入街道门牌号等信息" / class="col-xs-8">-->
					<textarea name="" rows="" cols="" class="col-xs-8" placeholder="请输入街道门牌号等信息" id="a_address"></textarea>
				</p>
			</div>
			<div class="chk">
				<input type="checkbox" id="cb" />
				<span>设为默认收货地址</span>
			</div>
			<button id="btn">保存</button>
		</div>
	</body>
	<script src="/home/js/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
	<script src="/home/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="/home/layer/layer.js"></script>
	<script type="text/javascript">
		var h=$(".chk span:nth-child(2)").height();
		var s=$(".chk span:nth-child(1)")
		s.width(h);
		s.height(s.width());
		s.css("line-height",h+"px")
	</script>
	<script>
		 
		$('#btn').click(function(){
			var a_name = $('#a_name').val();
			var a_tel = $('#a_tel').val();
			var a_region = $('#a_region').val();
			var a_address = $('#a_address').val();
			var reg = /^1[345678]\d{9}$/;
			var isChecked = $('#cb').prop('checked'); 

			if(isChecked==true){
				var a_status = 1;
			}else{
				var a_status = 2;
			}

			if(a_name===""){
				layer.msg('收货人姓名不能为空',{icon:5});
				return false;
			}else if(a_tel===""){
	            layer.msg('联系电话不能为空',{icon:5});
	            return false;
	        }else if(!reg.test(a_tel)){
	            layer.msg('联系电话格式错误',{icon:5});
	            return false;
	        }else if(a_region===""){
	            layer.msg('所在地区不能为空',{icon:5});
	            return false;
	        }else if(a_address===""){
	        	layer.msg('详细地址不能为空',{icon:5});
	            return false;
	        }else{
	        	$.post('/home/user/addAddressPost',{a_name:a_name,a_tel:a_tel,a_region:a_region,a_address:a_address,a_status:a_status},function(res){
	        		if(res.code==0){
	        			layer.msg(res.msg,{icon:6});
	        			setTimeout(function(){
                       	  window.location.href="/home/user/address";
                    	},1000);
	        		}else{
	        			layer.msg('服务器出错',{icon:5});
	        		}
	        	});
	        }
		});
	</script>
</html>